<?php
/*
	支付宝异步支付通知处理
*/
error_reporting(0);
//ini_set('display_errors', '1');
//error_reporting(E_ALL ^ E_NOTICE);
define('NOSESSION',true);
require '../../core/core.php';
set_exi(function($message='success',$type='success'){
	//如果存在错误，此处整理错误日志，后期完善
	if($type=='error'){
		$log=date('Y/m/d H:i:s');
		$log.="\t{$_SESSION['uniacid']}\t{$_SESSION['uid']}\t{$message}\n";
		file_put_contents('alipay_myerror_log.txt',$log,FILE_APPEND);
	}
	echo 'success';
	exit;
});
$pay_order=pdo_get('core_paylog',array('tid'=>trim($_GET['out_request_no'])));
if(!$pay_order){
	exi('指定订单不存在！','error');
}
$payfee=$pay_order['oldprice'];
if($payfee!=$_GET['total_freeze_amount']){
	$log=$pay_order['id'].'~'.$payfee.'~'.$_GET['total_freeze_amount']."\n";
	file_put_contents('alipay_myerror_log.txt',$log,FILE_APPEND);
	//exi('订单金额不匹配！','error');
}
$diyfields=json_decode($pay_order['diyfields'],true);
$_SESSION['uniacid']=$pay_order['uniacid'];
$_SESSION['uid']=$pay_order['mid'];
$_SESSION['this']='custom';
$check=model('jy_alipay/alipay')->check_sign($_GET);
if($check){
	if($_GET['auth_no']){
		$diyfields['auth_no']=$_GET['auth_no'];
		pdo_update('core_paylog',array('diyfields'=>ijson_encode($diyfields)),array('id'=>$pay_order['id']));
	}
}else{
	exi('签名校验失败！','error');
}